<template>
  <div >
    <form-head @onSubmit="onSubmit" :is_change="is_change"/>
    <el-form ref="form" :rules="rules" :model="form" label-width="130px" class="layout-all" :label-position="isMobile()?'top':'left'">
      <el-form-item label="商品名:" prop="title">
        <el-input v-model="form.title" placeholder="请输入商品名" class="form-width-50" />
      </el-form-item>
      <el-form-item label="封面图:" prop="thumb">
        <upload-pic :thumb="form.thumb" @update:thumb="form.thumb=$event" width="100" cate_id="2"/>
      </el-form-item>
      <el-form-item label="视频:" prop="video_id">
        <el-input v-model="video_name" :readonly="true" placeholder="请选择视频(需开通oss)" class="form-width"/>
        <el-link type="success" icon="el-icon-video-camera-solid" style="margin:0 10px" @click="logistics_isshow=true">选择视频</el-link>
        <el-tooltip class="item" effect="dark" content="清除已选择的视频" placement="top-start">
          <el-link type="danger" icon="el-icon-delete"  @click="del_select">清除</el-link>
        </el-tooltip>
      </el-form-item>
      <el-form-item label="轮播图:" prop="banners">
        <upload-banners :list="form.banners" @update="update_thumb"/>

        <div style="font-size:12px;">建议尺寸：420px X 420px</div>
      </el-form-item>
      <el-form-item label="展示价格:" prop="show_price">
        <el-input v-model="form.show_price" class="form-width-10" placeholder="请输入展示价格" />
      </el-form-item>
      <el-form-item label="销售价格:" prop="real_price">
        <el-input v-model="form.real_price" class="form-width-10" placeholder="请输入销售价格" />
      </el-form-item>
      <el-form-item label="商品结算价:" prop="cost_price">
        <el-input v-model="form.cost_price" class="form-width-10" placeholder="请输入商品结算价" />
      </el-form-item>
      <el-form-item label="以旧换新抵扣(0为禁用):" prop="swap_amount">
        <el-input v-model="form.swap_amount" class="form-width-10" placeholder="请输入以旧换新抵扣" />
      </el-form-item>
      <el-form-item label="商品货号:" prop="goods_sn">
        <el-input v-model="form.goods_sn" class="form-width-10" placeholder="默认自动生成" />
      </el-form-item>
      <el-form-item label="出售时间:" prop="sales_date">
        <el-date-picker
          v-model="form.sales_date"
          type="date"
          placeholder="选择出售时间"
          class="form-width-10"
          @change="dateChange()"
        />
      </el-form-item>
      <el-form-item label="介绍:" prop="description">
        <el-input v-model="form.description" class="form-width-10" placeholder="请输入介绍" />
      </el-form-item>
      <el-form-item label="商品关键词:" prop="keywords">
        <el-input v-model="form.keywords" class="form-width-10" placeholder="请输入商品关键词" />
      </el-form-item>
      <!-- 药品开始 -->
      <template v-if="pro_type==5">
        <el-card class="form-width" style="margin-bottom: 10px;">
          <div slot="header" class="clearfix">
            <span>药品</span>
          </div>
          <div>
            <el-form-item prop="is_prescription" label="是否处方药品:">
          <el-switch v-model="form.goods_append.is_prescription" />
        </el-form-item>
        <el-form-item label="药品规格:" prop="drug_spec">
          <el-input v-model="form.goods_append.drug_spec"  placeholder="请输入药品规格(如10mg*5片/盒)" />
        </el-form-item>
        <el-form-item label="用法用量" prop="usage">
          <el-input v-model="form.goods_append.usage"  placeholder="请输入用法用量" />
        </el-form-item>

          </div>
        
        </el-card>
      </template>
       <!-- 药品结束 -->
      <el-form-item prop="cate_t" label="系统分类:">
        <el-cascader
          v-model="selected_options"
          clearable
          :props="props_shop"
          :options="options"
          class="form-width-50"
          placeholder="请选择系统分类"
          @change="handleChange($event)"
        >
          <template slot-scope="{ node, data }">
            <span>{{ data.title }}</span>
            <span v-if="!node.isLeaf"> ({{ data.sub.length }}) </span>
          </template>
        </el-cascader>
      </el-form-item>
      <el-form-item label="店铺分类:" prop="shop_cate">
        <el-cascader
          v-model="shop_options"
          clearable
          :props="props_shop"
          :options="options2"
          placeholder="请选择店铺分类"
          @change="handleShopCate($event)"
        >
        </el-cascader>
      </el-form-item>
      <el-form-item label="点击量:" prop="pv">
        <el-input v-model="form.pv" class="form-width-10" placeholder="请输入点击量" />
      </el-form-item>
      <el-form-item label="虚拟销量:" prop="sale_inv">
        <el-input v-model="form.sale_inv" class="form-width-10" placeholder="请输入销量" />
      </el-form-item>
      <el-form-item label="运费:" prop="express_amount">
        <el-input v-model="form.express_amount" class="form-width-10" placeholder="请输入运费" />
      </el-form-item>
      <el-form-item v-if="id === 0" label="库存:" prop="stock">
        <el-input v-model="form.stock" class="form-width-10" placeholder="请输入库存" />
      </el-form-item>
      <el-form-item label="规格属性:" prop="">
        <el-tooltip class="item" effect="dark" content="规格是类型,如大小,颜色,属性即分类,如大,中,小,红,黄,蓝.设置后回到列表页面分别设置库存,售价,图标" placement="top-start">
        <el-button type="primary" @click="add_columnName()">添加规格</el-button>
        </el-tooltip>
      </el-form-item>
      <el-form-item v-if="spec_list.length !== 0" label="" prop="">
        <!-- <div class="spces_div"> -->
        <div v-for="(val,index) in spec_list" :key="index" class="spces_div form-80">
          <div style="margin-bottom:10px">
            <el-input v-model="val.title" class="form-width" placeholder="请输入规格" />
            <el-tooltip class="item" effect="dark" content="排序数字,由大到小" placement="top-start">
            <el-input-number v-model="val.sort" class="form-30" label="排序" />
            </el-tooltip>
            <!-- <el-input v-model="val.sort" style="width:25%" placeholder="排序" /> -->
            <el-tooltip class="item" effect="dark" content="可以添加多个属性,如红,黄,蓝" placement="top-start">
            <el-button style="margin-left:5px" type="text" @click="add_attribute(index)">添加属性</el-button>
            </el-tooltip>
            <el-button style="margin-left:5px" type="text" @click="del_columnName(index)">删除规格</el-button>
          </div>
          <div v-for="(v,i) in val.item" :key="i" style="margin-bottom:10px">
            <el-input v-model="v.title" class="form-width" placeholder="请输入属性" />
            <!-- <el-input v-model="v.sort" style="width:25%" placeholder="排序" /> -->
            <el-input-number v-model="v.sort" class="form-30" label="排序" />
            <el-button style="margin-left:5px" type="text" @click="del_attribute(index,i)">删除属性</el-button>
          </div>
        </div>
        <!-- </div> -->
      </el-form-item>

      <el-form-item label="设置">
          <el-checkbox prop="status" v-model="form.status" >是否启用</el-checkbox>
          <el-checkbox prop="is_choiceness" v-model="form.is_choiceness" >是否精选</el-checkbox>
          <el-checkbox prop="is_recommend" v-model="form.is_recommend" >是否推荐</el-checkbox>
          <el-checkbox prop="is_new" v-model="form.is_new" >是否新品</el-checkbox>
          <el-checkbox prop="is_hot" v-model="form.is_hot" >是否热卖</el-checkbox>
      </el-form-item>
      <el-form-item >
          <el-checkbox prop="group_is_commission" v-model="form.group_is_commission" >团购是否分佣</el-checkbox>
          <el-checkbox prop="special_is_commission" v-model="form.special_is_commission" >特价是否分佣</el-checkbox>
          <el-checkbox prop="seckill_is_commission" v-model="form.seckill_is_commission" >秒杀是否分佣</el-checkbox>
          <el-checkbox prop="is_not_level_dis" v-model="form.is_not_level_dis" >是否禁止等级打折</el-checkbox>
      </el-form-item>
      
      <el-form-item label="购买等级限制:" prop="level_info">
          购买最低等级
        <el-select v-model="level_min" clearable :disabled="level_max!=''"  placeholder="无限制" @change="is_change=true">
          <el-option
            v-for="item in level_info_list"
            :key="item.id"
            :label="item.title"
            :value="item.id">
          </el-option>
        </el-select>
         或不高于等级
        <el-select v-model="level_max" clearable :disabled="level_min!=''"  placeholder="无限制" @change="is_change=true">
          <el-option
            v-for="item in level_info_list"
            :key="item.id"
            :label="item.title"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>



      <el-form-item label="是否设置等级折扣:" prop="is_level_discount">
        <el-switch v-model="form.is_level_discount" />
        <el-radio-group v-model="level_discount.commission_type" v-if="form.is_level_discount">
          <el-radio-button  :label="0">按比例</el-radio-button>
          <el-radio-button :label="1">按金额</el-radio-button>
        </el-radio-group>

      </el-form-item>
      <el-form-item v-if="form.is_level_discount" >

        <el-form-item label-width="200px" :label="level_info[index].id+'级('+level_info[index].title+')比(%):'" v-for="(val,index) in level_discount.proportion" :key="index" v-if="level_discount.commission_type==0">
          <el-input v-model="level_discount.proportion[index]" class="form-width-10" placeholder="请输入折扣比(%)" />
        </el-form-item>
        <el-form-item label-width="200px" :label="level_info[index].id+'级('+level_info[index].title+')金额(元):'"  v-for="(val,index) in level_discount.fixed" :key="index" v-if="level_discount.commission_type==1">
          <el-input v-model="level_discount.fixed[index]" class="form-width-10" placeholder="请输入折扣(元)" />
        </el-form-item>
      </el-form-item>

        <el-card class="form-width-50" style="margin-bottom: 10px;">
          <div slot="header" class="clearfix">
            <span>分销设置</span>
          </div>
          <div>
            <el-form-item label="分销金额:" prop="distri_price">
        <el-input v-model="form.distri_price" class="form-width" placeholder="请输入分销金额" />
        <el-tag type="success">{{price_commission==1?'为0时按售价分销':'分销所使用金额,为0时不分销'}}</el-tag>
      </el-form-item>

      <el-form-item label="是否单独分佣:" prop="is_commission">
        <el-tooltip class="item" effect="dark" content="设置商品单独分佣则不参与平台设置的其它分佣,仅按推荐关系分配" placement="top-start">
        <el-switch v-model="form.is_commission" />
        </el-tooltip>
        <el-radio-group v-model="proportion.commission_type" v-if="form.is_commission" style="margin: 0 10px">
          <el-radio-button  :label="0">按比例分佣</el-radio-button>
          <el-radio-button :label="1">按金额分佣</el-radio-button>
        </el-radio-group>
        
          <el-radio-group v-model="proportion.type" v-if="form.is_commission" @change="change_comm_type" >
            <el-tooltip class="item" effect="dark" content="直推间推,以此类推" placement="top-start">
            <el-radio-button  :label="0">按推荐关系</el-radio-button>
             </el-tooltip>
             <el-tooltip class="item" effect="dark" content="判断上级等级分别分佣" placement="top-start">
            <el-radio-button :label="1">按级差</el-radio-button>
             </el-tooltip>
          </el-radio-group>
       

      </el-form-item>
      <el-form-item v-if="form.is_commission">
        <template v-if="proportion.type==0">
        <el-form-item label-width="200px" :label="(index+1)+'级分佣比(%):'" v-for="(val,index) in proportion.proportion" :key="index" v-if="proportion.commission_type==0">
          <el-input v-model="proportion.proportion[index]" class="form-width" placeholder="请输入分佣比(%)" />
        </el-form-item>
        <el-form-item label-width="200px" :label="(index+1)+'级分佣金额(元):'"  v-for="(val,index) in proportion.fixed" :key="index" v-if="proportion.commission_type==1">
          <el-input v-model="proportion.fixed[index]" class="form-width" placeholder="请输入分佣(元)" />
        </el-form-item>
        </template>
        <template v-else>
          <el-form-item label-width="200px" :label="level_info[index].id+'级('+level_info[index].title+')比(%):'" v-for="(val,index) in proportion.proportion" :key="index" v-if="proportion.commission_type==0">
          <el-input v-model="proportion.proportion[index]" class="form-width" placeholder="请输入分佣比(%)" />
        </el-form-item>
        <el-form-item label-width="200px" :label="level_info[index].id+'级('+level_info[index].title+')金额(元):'"  v-for="(val,index) in proportion.fixed" :key="index" v-if="proportion.commission_type==1">
          <el-input v-model="proportion.fixed[index]" class="form-width" placeholder="请输入分佣(元)" />
        </el-form-item>
        </template>
      </el-form-item>
          </div>
        </el-card>

      <el-form-item :label="'购买可用'+integral_name" prop="integral_buy" >
        <el-tooltip class="item" effect="dark" :content="'购买此商品最大可用的'+integral_name" placement="top-start">
        <el-input v-model="form.integral_buy" class="form-width-10"  placeholder="请输入数量" />
        </el-tooltip>
        <el-tag type="success">最大使用{{form.real_price*integral_scale}}个</el-tag>
      </el-form-item>
      <el-form-item :label="'购买赠送'+integral_name" prop="integral_give" >
        <el-tooltip class="item" effect="dark" :content="'购买此商品自动赠送的'+integral_name" placement="top-start">
        <el-input v-model="form.integral_give" class="form-width-10" placeholder="请输入数量" />
        </el-tooltip>
      </el-form-item>
      <el-form-item label="排序:" prop="sort">
        <el-input-number v-model="form.sort" class="form-width-10" label="排序" />
      </el-form-item>
      <el-form-item label="详情:" prop="content">
        <!-- <el-input
          v-model="form.content"
          type="textarea"
          :rows="3"
          placeholder="请输入详情"
        /> -->
        <!-- <rich_text /> -->
        <rich-text ref="myQuillEditor" :content="form.content" class="form-width-50" @change="is_change=true"/>
        <!-- <rich-text /> -->
      </el-form-item>
      <!-- <rich-text ref="myQuillEditor" :content="form.content" /> -->

    </el-form>
    <!-- 视频库 -->
    <drawer title="视频库" :isShow="logistics_isshow"  @update:isShow="logistics_isshow=false" width=".5">
      <video-manager @selectVideo="selectVideo"></video-manager>
    </drawer>
    <el-backtop ></el-backtop>
  </div>
</template>

<script>
import richText from '@/components/rich_text/rich_text'
import videoManager from "@/components/videoManager/videoManager";
import UploadBanners from "@/components/UploadPic/UploadBanners";
// import cutImageDialog  from "@/components/UploadPic/UploadPic";
export default {
  name:"GoodsForm",
  props:['model'],
  components: { richText, videoManager,UploadBanners },
  data() {
    return {
      logistics_isshow:false,
      video_name:'',
      pro_type:1,
      is_change: undefined,
      spec_list: [],
      list_thumb: [],
      integral_name: "积分",
      integral_scale: 1,
      price_commission: 0,
      id: 0,
      selected_options: [],
      options: [],
      options2: [],
      props_shop: {
        value: 'id',
        label: 'title',
        children: 'sub',
      },
      level_info: [],
      level_info_list: [],
      level_min: '',
      level_max: '',
      shop_options: [],
      thumb: '',
      RETAIL_LEVEL: 0,
      proportion: {
        commission_type:0,
        type:0,
        	fixed:[],
        	proportion:[],
      },
      level_discount: {
        commission_type:0,
        	fixed:[],
        	proportion:[],
      },
      form: {
        video_id:'',
        id: 0,
        shop_id: 0,
        cate_t1_id: 1,
        cate_t2_id: '',
        cate_t3_id: '',
        shop_cate_t1_id: '',
        shop_cate_t2_id: '',
        sales_date: '',
        status: true,
        is_hot: false,
        is_new: false,
        is_recommend: false,
        is_choiceness: false,
        sort: 1,
        title: '',
        thumb: '',
        banners: [],
        goods_append: {is_prescription:false},
        level_info: [],
        description: '',
        show_price: '',
        real_price: '',
        distri_price: 0.00,
        content: '',
        pv: 100,
        sale_inv: 0,
        stock: 100,
        is_commission: false,
        is_level_discount: false,
        group_is_commission: false,
        special_is_commission: false,
        seckill_is_commission: false,
        is_not_level_dis: false,
        integral_buy: 0,
        integral_give: 0,
        cost_price: 0,
        swap_amount: 0,
        express_amount: 0,
        keywords: '',
      },
      rules: {
        title: [
          { required: true, message: '请输入商品名', trigger: 'blur' }
        ],
        show_price: [
          { required: true, message: '请输入展示价格', trigger: 'blur' }
        ],
        real_price: [
          { required: true, message: '请输入销售价格', trigger: 'blur' }
        ],
        description: [
          { required: true, message: '请输入介绍', trigger: 'blur' }
        ],
        pv: [
          { required: true, message: '请输入点击量', trigger: 'blur' }
        ],
        sale_inv: [
          { required: true, message: '请输入销量', trigger: 'blur' }
        ],
        stock: [
          { required: true, message: '请输入库存', trigger: 'blur' }
        ],
        distri_price: [
          { required: true, message: '请输入分销金额', trigger: 'blur' }
        ],
        express_amount: [
          { required: true, message: '请输入运费', trigger: 'blur' }
        ],
      }
    }
  },
  mounted() {
    this.id = (this.$route.params && this.$route.params.id)||0
    this.$setTagsViewTitle(this.id)
    this.init_into()
  },
  methods: {
    //选择视频回调
    selectVideo (item) {
      this.form.video_id = item.id
      this.video_name = item.name
      this.logistics_isshow = false
    },
    //修改单独分佣推荐或级差
    change_comm_type (item) {
      this.proportion=this.setCommArray(this.proportion,item==0?this.RETAIL_LEVEL:this.level_info.length)
    },
    update_thumb(e,i){
      if(i<0){
        this.form.banners.push(e)
      }else{
        if(e==''){
          this.$delete(this.form.banners,i)
        }else{
          this.$set(this.form.banners,i,e)
        }
        
      }
    },
    del_select(){
      this.form.video_id = 0
      this.video_name = ''
    },
    // 出售时间
    dateChange() {
      const date = new Date(this.form.sales_date)
      const Y = date.getFullYear() + ''
      const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
      const D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate())
      this.form.sales_date = Y + '-' + M + '-' + D
    },
    // 获取种类id
    handleChange(event) {
      this.form.cate_t1_id = event[0]
      this.form.cate_t2_id = event[1]
      this.form.cate_t3_id = event[2]
    },
    // 提交
    onSubmit(formName) {
      const form = this.form
      form.content = this.$refs.myQuillEditor.editor_content

      this.$refs[formName].validate(valid => {
        if (valid) {
          form.id = this.id
          form.spec_list = this.spec_list
          form.status === true ? form.status = 1 : form.status = 0
          form.is_recommend === true ? form.is_recommend = 1 : form.is_recommend = 0
          form.is_choiceness === true ? form.is_choiceness = 1 : form.is_choiceness = 0
          form.is_new === true ? form.is_new = 1 : form.is_new = 0
          form.is_hot === true ? form.is_hot = 1 : form.is_hot = 0
          
          form.group_is_commission === true ? form.group_is_commission = 1 : form.group_is_commission = 0
          form.special_is_commission === true ? form.special_is_commission = 1 : form.special_is_commission = 0
          form.seckill_is_commission === true ? form.seckill_is_commission = 1 : form.seckill_is_commission = 0
          form.is_not_level_dis =form.is_not_level_dis ?1:0
          if(this.price_commission==0&&form.is_commission){
              this.$msg_ok('error','请设置分销金额后,再选单独分销')
              return
          }
          form.is_commission = form.is_commission?1:0
          form.proportion=this.proportion
          form.is_level_discount = form.is_level_discount?1:0
          form.level_discount=this.level_discount

          form.buy_level=this.level_max!=''?-this.level_max:this.level_min!=''?this.level_min:0
          if(this.video_name==''){
            form.video_id = 0
          }
          if(this.pro_type==5){
            this.form.goods_append.is_prescription=this.form.goods_append.is_prescription?1:0
          }
          //form.proportion.commission_type	=form.proportion.commission_type=== true ?1:0
          this.get('/'+this.model+'/Goods/save', form, 'POST').then(e => {
            this.$msg_ok('success', '操作成功')
            this.$back()
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
      console.log('submit!')
    },
    // 返回
    bk() {
      this.$router.back()
    },
    // 获取当前数据
    init_into() {
      let data={
        id:this.id,
      }
      this.get('/'+this.model+'/Goods/info',data, 'POST').then(e => {
        if(e==null)this.$router.back()
        this.options = e.cate
        this.options2 = e.shop_cate
        this.integral_name = e.integral_name
        this.integral_scale = e.integral_scale
        this.price_commission=e.price_commission
        this.pro_type=e.pro_type


        this.level_info=e.level_info
        this.level_info_list=this.level_info.concat()
        this.level_info_list.unshift({id:0,title:'无限制'})
        if(this.id>0){
          this.form = e.info.tpl
          if(this.form.buy_level<0){
            this.level_max=-this.form.buy_level
          }else if(this.form.buy_level>0){
            this.level_min=this.form.buy_level
          }
          this.spec_list = this.form.spec_list
          
          this.selected_options.push(this.form.cate_t1_id)
          this.selected_options.push(this.form.cate_t2_id)
          this.selected_options.push(this.form.cate_t3_id)

          this.shop_options.push(this.form.shop_cate_t1_id)
          // this.shop_options.push(this.form.shop_cate_t2_id)
          this.video_name = this.form.video_info ? this.form.video_info.name : ''
          this.form.status =this.form.status== 1
          this.form.is_recommend =this.form.is_recommend== 1
          this.form.is_choiceness =this.form.is_choiceness== 1
          this.form.is_new =this.form.is_new== 1
          this.form.is_hot =this.form.is_hot== 1
          this.form.is_commission =this.form.is_commission== 1
          this.form.is_level_discount =this.form.is_level_discount== 1
          this.form.group_is_commission =this.form.group_is_commission== 1
          this.form.special_is_commission =this.form.special_is_commission== 1
          this.form.seckill_is_commission =this.form.seckill_is_commission== 1
          this.form.is_not_level_dis =this.form.is_not_level_dis == 1
          this.form.banners=this.form.banners==''?[]:this.form.banners
          this.$refs.myQuillEditor.editor_content = this.form.content
          if(this.pro_type==5){
            if(!this.form.goods_append){
              this.form.goods_append={is_prescription:false}
            }else{
              this.form.goods_append.is_prescription=this.form.goods_append.is_prescription!=undefined&&this.form.goods_append.is_prescription==1
            }
          }
        }else{
          if(this.options2&&this.options2.length>0){
            this.form.shop_cate_t1_id=this.options2[0].id
            this.shop_options.push(this.form.shop_cate_t1_id)
          }else{
            this.msg_ok('error','请创建一个店铺分类')
          }
        }
        
        //分佣数组
        this.RETAIL_LEVEL = e.RETAIL_LEVEL
        if(e.proportion!=null){
          this.proportion=e.proportion
          //this.proportion.commission_type	=this.proportion.commission_type== 1 ?true:false
        }
        this.proportion=this.setCommArray(this.proportion,this.proportion.type==0?this.RETAIL_LEVEL:this.level_info.length)

        //等级折扣
        if(e.level_discount!=null){
          this.level_discount=e.level_discount
        }
        this.level_discount=this.setCommArray(this.level_discount,this.level_info.length)

       
       setTimeout(()=>{this.is_change=false},100) 
      })
    },
    //转换数组长度
    setCommArray(arr,length){
      let count=length-arr.fixed.length
      if(count<0){
        arr.fixed=arr.fixed.slice(0,length)
      }else if(count>0){
        for(let i=0 ;i<count;i++){
          arr.fixed.push(0)
        }
      }
      count=length-arr.proportion.length
      if(count<0){
        arr.proportion=arr.proportion.slice(0,length)
      }else if(count>0){
        for(let i=0 ;i<count;i++){
          arr.proportion.push(0)
        }
      }
      return arr
    },
    // 商品分类赋值
    handleShopCate(val) {
      this.form.shop_cate_t1_id = val[0]
      this.form.shop_cate_t2_id = val[1]
    },
    //
    onEditorReady(editor) {
    },
    // 添加类型
    add_columnName() {
      this.spec_list.push({
        id: 0,
        title: '',
        sort: 1,
        item: [{ id: 0, title: '', sort: 0 }]
      })
    },
    // 删除规格
    del_columnName(index) {
      this.spec_list.splice(index, 1)
    },
    // 添加属性
    add_attribute(index) {
      this.spec_list[index].item.push({ id: 0, title: '', sort: 0 })
    },
    // 删除属性
    del_attribute(index, i) {
      if (this.spec_list[index].item.length > 1) {
        this.spec_list[index].item.splice(i, 1)
        return false
      }
      this.$msg_confirm('该规格只有一条属性,如果删除,规格也会删除,是否删除?').then(e => {
        this.spec_list.splice(index, 1)
      })
    }
  },
  watch: {
    form:{
      handler (val, oldVal) {
        if(this.is_change!=undefined)
          this.is_change=true
      },
      deep:true
    },
    level_discount:{
      handler (val, oldVal) {
        if(this.is_change!=undefined)
          this.is_change=true
      },
      deep:true
    },
    proportion:{
      handler (val, oldVal) {
        if(this.is_change!=undefined)
          this.is_change=true
      },
      deep:true
    },
  }
}
</script>

<style >


@media (max-width:550px) {
  .form-80{
    width: 100% !important;

  }
  .form-30{
    width: 40% !important;
  }
}
.form-30{
    width: 30% ;
  }
.layout-all {
  margin: 20px;
}
.spces_div{
  border:1px solid #DCDFE6;
  height: 100%;
  width: 30%;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
}
.avatar-uploader {
  width:110px;
  height:110px;
}
.avatar-uploader .el-upload--picture-card {
  width:110px;
  height:110px;
}
.avatar_item img{
  width:110px;
  height:110px;
}
</style>
